import {
    createRouter,
    createWebHistory
} from 'vue-router';
import Index from '../views/Index.vue';
import BusinessList from '../views/BusinessList.vue';
import BusinessInfo from '../views/BusinessInfo.vue';
import Login from '../views/Login.vue';
import Orders from '../views/Orders.vue';
import UserAddress from '../views/UserAddress.vue';
import Payment from '../views/Payment.vue';
import OrderList from '../views/OrderList.vue';
import AddUserAddress from '../views/AddUserAddress.vue';
import EditUserAddress from '../views/EditUserAddress.vue';
import Register from '../views/Register.vue';
import Mine from '../views/Mine.vue';
import PointsDetails from '../views/PointsDetails.vue';
import FoodAdmin from '../views/FoodAdmin.vue';
import Error403 from '../components/Error403.vue';
import Wallet from '../views/Wallet.vue'
import PointsShop from '@/views/PointsShop.vue';
import CommentPage from '@/views/comment.vue';
import RiderOrders from '@/views/RiderOrders.vue';

const routes = [{
    path: '/',
    name: 'Home',
    component: Index
}, {
    path: '/index',
    name: 'Index',
    component: Index
}, {
    path: '/businessList',
    name: 'BusinessList',
    component: BusinessList
}, {
    path: '/businessInfo',
    name: 'BusinessInfo',
    component: BusinessInfo
}, {
    path: '/login',
    name: 'Login',
    component: Login
}, {
    path: '/orders',
    name: 'Orders',
    component: Orders
}, {
    path: '/userAddress',
    name: 'UserAddress',
    component: UserAddress
}, {
    path: '/add-food',
    name: 'AddFood',
    component: () => import('../views/AddFood.vue')
},
    {
        path: '/edit-food/:foodId',
        name: 'EditFood',
        component: () => import('../views/EditFood.vue')
    },{
        path: '/foodadmin',
        name: 'FoodAdmin',
        component: FoodAdmin
    },{
        path: '/payment',
        name: 'Payment',
        component: Payment
    }, {
        path: '/orderList',
        name: 'OrderList',
        component: OrderList
    }, {
        path: '/addUserAddress',
        name: 'AddUserAddress',
        component: AddUserAddress
    }, {
        path: '/editUserAddress',
        name: 'EditUserAddress',
        component: EditUserAddress
    }, {
        path: '/register',
        name: 'Register',
        component: Register
    }, {
        path: '/Mine',
        name: 'Mine',
        component: Mine
    },{
        path: '/pointsDetails',
        name: 'PointsDetails',
        component: PointsDetails
    },{
        path: '/error403',
        name: 'Error403',
        component: Error403
    },{
        path: '/wallet',
        name: 'Wallet',
        component: Wallet
    },{
        path: '/pointsshop',
        name: 'PointsShop',
        component: PointsShop
    },{
        path: '/comment',
        name: 'Comment',
        component: CommentPage
    },{
        path: '/riderorders',
        name: 'riderorders',
        component: RiderOrders
    }

];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            // 如果存在保存的滚动位置，则恢复到该位置
            return savedPosition;
        } else {
            // 否则滚动到页面顶部
            return { left: 0, top: 0 };
        }
    },
});



export default router;